package com.example.buildtable.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.buildtable.mapper.MemberMapper;
import com.example.buildtable.pojo.Member;
import com.example.buildtable.pojo.User;
import com.example.buildtable.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {
    @Autowired
    private MemberMapper memberMapper;

    @Override
    public Map<String, Object> login(Member member) {
        Map<String, Object> map = new HashMap<>();
        //条件处理
        QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("member_account", member.getMemberAccount());
        Member members = memberMapper.selectOne(queryWrapper);
        //没有用户
        if (members == null) {
            map.put("state", "nourse");
        } else {
            //有用户，判断密码是否正确
            if (members.getPassword().equals(member.getPassword())) {
                map.put("state", "success");
            } else {
                map.put("state", "error");
            }
        }
        return map;
    }
}